package javapop.framework.parser;

import javapop.framework.ParseContext;
import javapop.framework.ParseError;
import javapop.framework.ParseInput;
import javapop.framework.ParseNull;
import javapop.framework.ParseResult;
import javapop.framework.Parser;

public class EOF extends Parser<Object> {
	private static EOF singleton = new EOF();
	
	private EOF() {
	}
	
	public static EOF getInstance() {
		return singleton;
	}

	@Override
	public String getDescription() {
		return "EOF";
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ParseResult<?> eval(ParseContext ctx, ParseInput input) {
		if(input.isEOF()) {					
			return new ParseNull();
		} else {
			ParseResult error = new ParseError("Expecting "+getDescription());
			return (ParseResult<String>) error;
		}
	}
	
	@Override
	public boolean isMemoized() {
		return true;
	}
	
	
}
